package student.aistar.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:
 * @Auther: zhugefeng
 * @Date:2021/10/12 10:24
 **/
@ControllerAdvice
public class GlobalExceptionHandler {

//    @ExceptionHandler(value = Exception.class)
//    @ResponseBody
//    public Result handler(){
//        System.out.println("==============");
//        return new Result("500","sorry,server is update");
//    }

    /**
     * 测试阶段...
     * @param
     * @return
     */
//    @ExceptionHandler(value = Exception.class)
//    @ResponseBody
//    public Result handler(Exception e){
//        System.out.println("==============");
//        return new Result("500","sorry,server is update",e.getMessage());
//    }

    @ExceptionHandler(value = Exception.class)
    public void  handler(HttpServletResponse response){
        //servlet代码中重定向
        try {
            response.sendRedirect("/mi/error/error.html");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
